// 字典管理路由
import { Router } from 'express';
import dictController from '@/controllers/system/dict.controller';
import { authMiddleware } from '@/middlewares/auth.middleware';
import { permissionMiddleware } from '@/middlewares/permission.middleware';
import { validateDictTypeCreate, validateDictTypeUpdate, validateDictTypeRemove, validateDictTypeInfo,
         validateDictDataCreate, validateDictDataUpdate, validateDictDataRemove, validateDictDataInfo,
         validateDictType } from '@/validators/system/dict.validator';
import { createController } from '@/utils/router/route.controller';

const router = createController(Router());

/**
 * 字典管理路由
 * 路径前缀：/system/dict
 */

// ================== 字典类型相关 ==================

// 类型列表
router.get('/type/list', authMiddleware, permissionMiddleware('system:dict:list'), dictController.listType);

// 类型下拉选择框
router.get('/type/optionselect', authMiddleware, permissionMiddleware('system:dict:list'), dictController.optionselect);

// 类型详情
router.get('/type/:dictId', authMiddleware, permissionMiddleware('system:dict:query'), validateDictTypeInfo, dictController.getType);

// 新增类型
router.POST('/type', authMiddleware, permissionMiddleware('system:dict:add'), validateDictTypeCreate, dictController.addType);

// 修改类型
router.PUT('/type', authMiddleware, permissionMiddleware('system:dict:edit'), validateDictTypeUpdate, dictController.updateType);

// 刷新缓存
router.DELETE('/type/refreshCache', authMiddleware, dictController.refreshCache);

// 删除类型
router.DELETE('/type/:dictId', authMiddleware, permissionMiddleware('system:dict:remove'), validateDictTypeRemove, dictController.removeType);

// 导出字典类型数据
router.post('/type/export', authMiddleware, permissionMiddleware('system:dict:export'), dictController.exportType);

// ================== 字典数据相关 ==================
// 根据字典类型查询字典数据
router.get('/data/type/:dictType', validateDictType, dictController.type);

// 数据列表
router.get('/data/list', authMiddleware, permissionMiddleware('system:dict:list'), dictController.listData);

// 数据详情
router.get('/data/:dictCode', authMiddleware, permissionMiddleware('system:dict:query'), validateDictDataInfo, dictController.getData);

// 新增数据
router.POST('/data', authMiddleware, permissionMiddleware('system:dict:add'), validateDictDataCreate, dictController.addData);

// 修改数据
router.PUT('/data', authMiddleware, permissionMiddleware('system:dict:edit'), validateDictDataUpdate, dictController.updateData);

// 删除数据
router.DELETE('/data/:dictCode', authMiddleware, permissionMiddleware('system:dict:remove'), validateDictDataRemove, dictController.removeData);

// 导出字典数据
router.post('/data/export', authMiddleware, permissionMiddleware('system:dict:export'), dictController.exportData);

export default router; 